package com.zhouchao.dubbo;

import com.zhouchao.dubbo.filter.TPMonitorFilter;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @Author: zhouchao
 * @Date: 2021/09/18 14:34
 * @Description:
 */
@Slf4j
@DubboComponentScan
@SpringBootApplication
public class ConsumerApplication implements CommandLineRunner {

    public static final TPMonitorFilter monitorTime = ExtensionLoader.getExtensionLoader(TPMonitorFilter.class).getExtension("monitorTime");


    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        startMonitor();
    }

    private void startMonitor() {

        while (true){
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            log.info("methodA-TP90:{}",monitorTime.getTP90("com.zhouchao.dubbo.HelloService.methodA"));
            log.info("methodA-TP99:{}",monitorTime.getTP99("com.zhouchao.dubbo.HelloService.methodA"));

            log.info("methodB-TP90:{}",monitorTime.getTP90("com.zhouchao.dubbo.HelloService.methodB"));
            log.info("methodB-TP99:{}",monitorTime.getTP99("com.zhouchao.dubbo.HelloService.methodB"));

            log.info("methodC-TP90:{}",monitorTime.getTP90("com.zhouchao.dubbo.HelloService.methodC"));
            log.info("methodC-TP99:{}",monitorTime.getTP99("com.zhouchao.dubbo.HelloService.methodC"));

        }
    }


}
